package edu.neu.javaweb.dao;

import edu.neu.javaweb.bean.Dept;
import io.github.biezhi.anima.Anima;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class DeptDao {
    public List<Dept> findAll() {

        return Anima.select().bySQL(Dept.class, "select * from dept_zh").all();

    }

    public Dept findById(int id) {

        return Anima.select().bySQL(Dept.class, "select * from dept_zh where id=?", id).all().get(0);

    }

    public void add(Dept dept) {
        String sql = "insert into dept_zh (name, loc) values (?, ?)";
        Anima.execute(sql, dept.getName(), dept.getLoc());

    }

    public void deleteById(int id) {
        String sql = "delete from dept_zh where id=?";
        Anima.execute(sql, id);

    }

    public void update(Dept dept) {
        String sql = "update dept_zh set name=?, loc=? where id=?";
        Anima.execute(sql, dept.getName(), dept.getLoc(), dept.getId());

    }
}

